import 'package:vischat/core/constants/storage_constants.dart';
import 'package:vischat/core/service/storage/base_secure_storage.dart';

/// 加密存储token
class SecureAuthStorage extends BaseSecureStorage {
  SecureAuthStorage()
    : super(
        boxName: 'encrypted_auth_storage',
        encryptionKeyName: 'hive_auth_key',
      );

  // token
  Future<void> saveToken(String token) async {
    await saveData(StorageConstants.auth_token, token);
  }

  String? getToken() => getData(StorageConstants.auth_token);
  Future<void> deleteToken() async => await delete(StorageConstants.auth_token);

  // 用户
  Future<void> saveUser(Map<String, dynamic> userInfo) async {
    await saveData(StorageConstants.user, userInfo);
  }

  Map<String, dynamic>? getUser() {
    final data = getData(StorageConstants.user);
    return data != null ? Map<String, dynamic>.from(data) : null;
  }
  Future<void> deleteUser() async => await delete(StorageConstants.user);
}
